<%@page import="com.shsh.safemanage.util.Util"%>
<%@page import="java.util.ArrayList"%>
<%@page import="com.shsh.safemanage.util.Constants"%>
<%@page import="com.shsh.safemanage.dao.DaoCreator"%>
<%@page import="com.shsh.safemanage.dao.AccidentDao"%>
<%@page import="com.shsh.safemanage.model.AccidentCasualty"%>
<%@page import="java.util.List"%>
<%@ page language="java" pageEncoding="UTF-8"%>
<%
{
	AccidentDao innerAccidentDao = DaoCreator.createAccidentDao();
	List<AccidentCasualty> innerCasualtyList = (List<AccidentCasualty>)request.getSession().getAttribute(Constants.SESSION_ACCIDENT_CASUALTY);
	if(innerCasualtyList == null){
		innerCasualtyList = new ArrayList<AccidentCasualty>();
	}
	
%>
<table align="center" border="1"  width="100%" cellpadding="0" cellspacing="0">
<%
	for(int i=0;i<innerCasualtyList.size(); i++) {
		AccidentCasualty innerCasualty = innerCasualtyList.get(i);
%>
	<tr>
		<td class="td1" style="width:9%;text-align:center;">
			姓名
		</td>
		<td class="td1" style="width:9%;text-align:center;">
			<%=Util.getDisplay(innerCasualty.getName(), "&nbsp;") %>
		</td>
		<td class="td1" style="width:9%;text-align:center;">
			性别
		</td>
		<td class="td1">
			<%
			if(innerCasualty.getGender()!=null && innerCasualty.getGender() == 1) {
			%>
			男
			<%
			} else if(innerCasualty.getGender()!=null && innerCasualty.getGender() == 2) {
			%>
			女
			<%
			} else {
			%>
			&nbsp;
			<%
			}
			%>
		</td>
		<td class="td1" style="width:9%;text-align:center;">
			年龄
		</td>
		<td class="td1">
			<%=Util.getDisplay(innerCasualty.getAge(), "&nbsp;") %>
		</td>
		<td class="td1" style="width:9%;text-align:center;">
			工龄
		</td>
		<td class="td1">
			<%=Util.getDisplay(innerCasualty.getWorkAge(), "&nbsp;") %>
		</td>
		<td class="td1" style="width:9%;text-align:center;">
			工种
		</td>
		<td class="td1">
			<%=Util.getDisplay(innerCasualty.getWorkType(), "&nbsp;") %>
		</td>
		<td class="td1" style="text-align:center;">
			<a href="#" onclick="deleteAccidentCasualty(<%=i%>)">删除</a>
		</td>
	</tr>
	<tr>
		<td class="td1" colspan="2" style="text-align:center;">
			受伤部位及伤害性质
		</td>
		<td class="td1" colspan="4">
			<textarea  rows="3" style="width:90%; margin-bottom:5px;" id="casualtDetail"><%=Util.getDisplay(innerCasualty.getCasualtyDetail(), "&nbsp;") %></textarea>
		</td>
		<td class="td1" colspan="3" style="text-align:center;">
			严重程度
		</td>
		<td class="td1">
			<textarea  rows="3" style="width:90%; margin-bottom:5px;" id="seriousLevel"><%=Util.getDisplay(innerCasualty.getSeriousLevel(), "&nbsp;") %></textarea>
		</td>
		<td class="td1">&nbsp;</td>
	</tr>
<%
	}
%>
	<tr>
		<td class="td1" style="width:9%;text-align:center;">
			姓名
		</td>
		<td class="td1" style="width:9%;text-align:center;">
				<input id="casualtyName" name="casualtyName" type="text" style="width:60px;" value=""/>
		</td>
		<td class="td1" style="width:9%;text-align:center;">
			性别
		</td>
		<td class="td1" style="width:5%;text-align:center;">
				<select id="gender">
					<option value="1">男</option>
					<option value="2">女</option>
				</select>
		</td>
		<td class="td1" style="width:9%;text-align:center;">
			年龄
		</td>
		<td class="td1" style="width:5%;text-align:center;">
				<input id="age" name="age" type="text"  style="width:30px;" value=""/>
		</td>
		<td class="td1" style="width:9%;text-align:center;">
			工龄
		</td>
		<td class="td1" style="width:5%;text-align:center;">
				<input id="workAge" name="workAge" type="text" style="width:30px;" value=""/>
		</td>
		<td class="td1" style="width:9%;text-align:center;">
			工种
		</td>
		<td class="td1" style="width:18%;text-align:center;">
				<input id="workType" name="workType" type="text" value=""/>
		</td>
		<td class="td1" style="text-align:center;">
			<a href="#" onclick="addAccidentCasualty()">添加</a>
		</td>
	</tr>
	<tr>
		<td class="td1" colspan="2" style="text-align:center;">
			受伤部位及伤害性质
		</td>
		<td class="td1" colspan="4" style="text-align:center;">
			<textarea id="casualtDetail"  rows="3" style="width:90%; margin-bottom:5px;"></textarea>
		</td>
		<td class="td1" colspan="3" style="text-align:center;">
			严重程度
		</td>
		<td class="td1" style="text-align:center;">
			<textarea id="seriousLevel"  rows="3" style="width:90%; margin-bottom:5px;"></textarea>
		</td>
		<td class="td1">&nbsp;</td>
	</tr>
</table>
<script type="text/javascript">
function deleteAccidentCasualty(casualtyIndex){
	openWaitingDialog('waitingDialog');
	$.ajax({
		type:'post',
		url:'<%=request.getContextPath()%>/accident/accident_casualty_delete.jsp',
		data:{
			casualtyIndex: casualtyIndex
		},
		success:function(data,state,xmlhttp){
			var obj = null;
			try {
				obj = eval('(' + data + ')');
			} catch (e) {
			}
			if (typeof(obj.isSuccess) != 'undefined') {
				if (obj.isSuccess == 'true') {
					loadPageSection('<%=request.getContextPath()%>/accident/accident_casualty.jsp', 'accidentCasualtyDiv', {}, false,
					function() {
						
					});
				} else {
					$.dialog.alert(obj.error);
				}
				closeWaitingDialog('waitingDialog');
			}
		}
	});	
}
function addAccidentCasualty(){
	var casualtyName = getElementValueByID("casualtyName");
	var gender = getElementValueByID("gender");
	var age = getElementValueByID("age");
	var workAge = getElementValueByID("workAge");
	var workType = getElementValueByID("workType");
	var casualtDetail = getElementValueByID("casualtDetail");
	var seriousLevel = getElementValueByID("seriousLevel");
	

	var strExp = <%=Constants.REGX_AGE%>;
	if(age == null ||  age == '' || age == 'undefined') {
		// empty.
	} else {
		if (!strExp.test(age)){
			$.dialog.alert('年龄必须为正整数');
			return;
		}		
	}
	
	if(workAge == null ||  workAge == '' || workAge == 'undefined') {
		// empty.
	} else {
		if (!strExp.test(workAge)){
			$.dialog.alert('工龄必须为正整数');
			return;
		}		
	}
	
	if(casualtyName == null || casualtyName == '' || casualtyName == 'undefined') {
		$.dialog.alert('请填写姓名');
		return;
	}
	
	openWaitingDialog('waitingDialog');
	$.ajax({
		type:'post',
		url:'<%=request.getContextPath()%>/accident/accident_casualty_add.jsp',
		data:{
			casualtyName: casualtyName,
			gender: gender,
			age: age,
			workAge: workAge,
			workType: workType,
			casualtDetail: casualtDetail,
			seriousLevel: seriousLevel
		},
		success:function(data,state,xmlhttp){
			var obj = null;
			try {
				obj = eval('(' + data + ')');
			} catch (e) {
			}
			if (typeof(obj.isSuccess) != 'undefined') {
				if (obj.isSuccess == 'true') {
					loadPageSection('<%=request.getContextPath()%>/accident/accident_casualty.jsp', 'accidentCasualtyDiv', {}, false,
					function() {
						
					});
				} else {
					$.dialog.alert(obj.error);
				}
				closeWaitingDialog('waitingDialog');
			}
		}
	});
}
</script>
<%
}
%>